#include <iostream>
#include <cstring>
#include <algorithm>

const int N = 305;
const int M = 1 << 17 | 5;
const int P = 1e9 + 7;

int n, m;
int a[N][N];
int f[N][M], g[N][M], val[M], h[N];
int ans[N][N];

inline void upd(int& x, int y) {
	x += y;
	if(x > P) x -= P; 
}

void solve(int n, int m, int f[N][M]) {
	//std::memset(f, 0, sizeof f);
	f[0][0] = 1;
	for(int i = 1; i <= n; ++i) {
		for(int s = 0; s < (1 << m); ++s) f[i][s] = f[i-1][s];
		//std::cerr << "i = " << i << "\n";
		for(int j = 1; j <= m; ++j) {
			for(int s = 0; s < (1 << m); ++s) {
				if(s >> (j-1) & 1) upd(f[i][s^(1<<j-1)], f[i][s]);
			}
		}
		for(int s = 0; s < (1 << m); ++s) {
			for(int j = 1; j <= m; ++j) {
				if((s >> (j - 1) & 1) && a[i][j] != a[i-1][j]) {
					f[i][s] = 0;
				}
			}
		}
		for(int j = 1; j <= m; ++j) {
			for(int s = 0; s < (1 << m); ++s) {
				if(!(s >> j-1 & 1)) upd(f[i][s^(1<<j-1)], f[i][s]);
			}
		}
		for(int s = 0; s < (1 << m); ++s) {
			//std::cerr << s << " " << f[s] << "\n";
			int c = 0;
			int t = 1;
			for(int j = 1; j <= m; ++j) {
				if(!(s >> j-1 & 1)) {
					if(a[i][j] == a[i][j-1]) {
						++c;
					} else {
						t *= h[c];
						c = 1;
					}
				} else {
					t *= h[c];
					c = 0;
				}
			}
			t *= h[c];
			f[i][s] = 1ll * f[i][s] * t % P;
			//std::cerr << s << " " << f[s] << "\n";
		}
	}
	/*
	int ans = 0;
	for(int s = 0; s < (1 << m); ++s) upd(ans, f[s]);
	return ans % P;
	*/
}

int t[M];

int getans(int n, int m, int i) {
	for(int s = 0; s < (1 << m); ++s) t[s] = f[i-1][s];
	int st = 0;
	for(int j = 1; j <= m; ++j) if(a[i][j] != a[i-1][j]) st |= 1 << (j-1);
	for(int s = 0; s < (1 << m); ++s) {
		if(s & st) t[s] = 0;
	}
	for(int j = 1; j <= m; ++j) {
		for(int s = 0; s < (1 << m); ++s) {
			if(!(s >> j-1 & 1)) upd(t[s^(1<<j-1)], t[s]);
		}
	}
	//slow
	st = 0;
	for(int j = 1; j <= m; ++j) if(a[i][j] == a[i][j-1]) st |= 1 << j;
	for(int s = 0; s < (1 << m); ++s) {
		int c = 0;
		int tt = 1;
		for(int j = 1; j <= m; ++j) {
			if(!(s >> j-1 & 1)) {
				if(st >> j & 1) {
					++c;
				} else {
					tt *= h[c];
					c = 1;
				}
			} else {
				tt *= h[c];
				c = 0;
			}
			if(!tt) break;
		}
		tt *= h[c];
		t[s] = 1ll * t[s] * tt % P;
		//std::cerr << s << " " << f[s] << "\n";
	}
	for(int j = 1; j <= m; ++j) {
		for(int s = 0; s < (1 << m); ++s) {
			if(s >> j-1 & 1) {
				upd(t[s^(1<<j-1)], t[s]);
			}
		}
	}
	st = 0;
	for(int j = 1; j <= m; ++j) if(a[i][j] != a[i+1][j]) st |= 1 << j-1;
	int res = 0;
	for(int s = 0; s < (1 << m); ++s) {
		if(s & st) t[s] = 0;
		res = (res + 1ll * t[s] * g[i+1][s]) % P;
	}
	return res;
}

int main() {
	std::freopen("disanti.in", "r", stdin);
	std::freopen("disanti.out", "w", stdout);
	std::cin >> n >> m;
	h[0] = 1;
	for(int i = 1; i <= std::min(n, m); ++i) {
		for(int j = 2; j <= i; ++j) upd(h[i], h[i-j]);
	}
	if(n < m) {
		for(int i = 1; i <= n; ++i) {
			for(int j = 1; j <= m; ++j) {
				char ch; std::cin >> ch;
				a[j][i] = ch - '0';
			}
		}
		solve(m, n, f);
		std::reverse(a + 1, a + m + 1);
		solve(m, n, g);
		std::reverse(g, g + m + 2);
		std::reverse(a + 1, a + m + 1);
		for(int i = 1; i <= m; ++i) {
			for(int j = 1; j <= n; ++j) {
				for(int s = 0; s < (1 << n); ++s) {
					if(s >> j-1 & 1) {
						upd(g[i+1][s^(1<<j-1)], g[i+1][s]);
						upd(f[i-1][s^(1<<j-1)], f[i-1][s]);
					}
				}
			}
			for(int j = 1; j <= n; ++j) {
				a[i][j] ^= 1;
				ans[j][i] = getans(m, n, i);
				a[i][j] ^= 1;
			}
		}
		/*
		   for(int i = 1; i <= n; ++i) {
		   for(int j = 1; j <= m; ++j) {
		   a[j][i] ^= 1;
		   std::cout << solve(m, n) << " \n"[j == m];
		   a[j][i] ^= 1;
		   }
		   }
		 */
	} else {
		for(int i = 1; i <= n; ++i) {
			for(int j = 1; j <= m; ++j) {
				char ch; std::cin >> ch;
				a[i][j] = ch - '0';
			}
		}
		solve(n, m, f);
		std::reverse(a + 1, a + n + 1);
		solve(n, m, g);
		std::reverse(g, g + n + 2);
		std::reverse(a + 1, a + n + 1);
		for(int i = 1; i <= n; ++i) {
			for(int j = 1; j <= m; ++j) {
				for(int s = 0; s < (1 << m); ++s) {
					if(s >> j-1 & 1) {
						upd(g[i+1][s^(1<<j-1)], g[i+1][s]);
						upd(f[i-1][s^(1<<j-1)], f[i-1][s]);
					}
				}
			}
			for(int j = 1; j <= m; ++j) {
				a[i][j] ^= 1;
				ans[i][j] = getans(n, m, i);
				a[i][j] ^= 1;
			}
		}
		/*
		   for(int i = 1; i <= n; ++i) {
		   for(int j = 1; j <= m; ++j) {
		   a[i][j] ^= 1;
		   std::cout << solve(n, m) << " \n"[j == m];
		   a[i][j] ^= 1;
		   }
		   }
		 */
	}
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			std::cout << ans[i][j] << " \n"[j == m];
		}
	}
	return 0;
}
